//债券信息维护
import api from '../../api';
import { message } from 'antd';
import { resolveOnChange } from 'antd/lib/input/Input';
import uuid from 'es6-uuid';
export default {
  namespace: 'manbondInfoM',
  state: {},
  effects: {
    //查询债券信息维护的表格
    *getDataList({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.bondInfoList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback();
        message.error(res ? res.msg || '查询列表失败!' : '查询列表失败!');
      }
    },

    //查询债券信息维护的表格
    *bondInfoListAdd({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.bondInfoListAdd, payload);
      if (res && res.code == 0) {
        callback(res);
        message.success(res.msg || '操作成功！');
      } else {
        message.error(res?.msg);
      }
    },

    //根据证券代码进行数据回填
    *bondInfoDetail({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.bondInfoDetail, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg);
      }
    },

    //债券信息维护批量确认
    *bondInfoListConfirm({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.bondInfoListConfirm, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res?.msg || '批量确认失败');
      }
    },
    //删除
    *deleteById({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.deleteById, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        message.error(res?.msg || '删除失败');
      }
    },
    //获取同发行人数据
    *getVerifyData({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.getVerifyData, payload);
        if(res?.code===0){
        res.data?.map(item=>{
          item.id=uuid(16)
          item.childData.map(x=>x.pid=item.id);//每个子表行都存储父表的id
        })
        callback(res.data);
      } else {
        callback()
        message.error(res?.msg || '获取发行人列表失败!');
      }
    },
    //保存 发行人修改字段
    *saveVerifyData({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.saveVerifyData, payload);
      if(res?.code===0){
        callback();
      } else {
        message.error(res?.msg || '保存失败!');
      }
    },
     //获取资讯校验数据
     *getInfoData({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.getInfoData, payload);
   
      if(res?.code===0){
        
        res.data?.dataSource.map(item=>{
          item.key=uuid(16)
        })
        callback(res.data);
      } else {
        callback()
        message.error(res?.msg || '获取资讯列表失败!');
      }
    },
    //保存资讯数据
    *saveInfoData({ payload, callback }, { call, put }) {
      const res = yield call(api.manbondInfo.saveInfoData, payload);
    
      if(res?.code===0){
        callback();
      } else {
        message.error(res?.msg || '保存失败!');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
